import { ProFormSelect, ProFormSelectProps } from '@ant-design/pro-components';
import React from 'react';
import { convertValue, getSelectList, transformValue } from '@/util/util';
import { getList as getUserList } from '@/services/system/user';

type MyOrgSelectProps = {
  required?: boolean;
  requiredMsg?: string;
} & ProFormSelectProps;
const MyUserSelect: React.FC<MyOrgSelectProps> = ({
  label = '负责人',
  name = 'directorId',
  required = true,
  requiredMsg,
  ...restProps
}) => {
  return (
    <ProFormSelect
      label={label}
      name={name}
      convertValue={(value) => convertValue(value)}
      transform={(value) => transformValue(value)}
      request={(params) =>
        getSelectList<Omit<USER_TYPE.Info, 'roleId'>>({
          label: 'title',
          value: 'id',
          server: () => getUserList(params),
        })
      }
      rules={[
        {
          required: required,
          message: requiredMsg || `${label}为必选项`,
        },
      ]}
      {...restProps}
    />
  );
};

export default MyUserSelect;
